package com.mlick.a.algorithm;

import java.util.Arrays;

/**
 * @author lixiangxin
 * @date 2019/3/27 10:05
 **/
public class BinarySearch {


    public static int rank(int k, int[] a) {
        int lo = 0;
        int hi = a.length - 1;

        while (lo <= hi) {
            int mid = lo + (hi - lo) / 2;
            if (k < a[mid]) {
                hi = mid - 1;
            } else if (k > a[mid]) {
                lo = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }


    public static void main(String[] args) {

        int r[] = {1};
        Arrays.sort(r);


        System.out.println(r[rank(0,r)]);
    }
}
